package org.example.communication_room.repository;

import org.example.communication_room.dao.Friendship;
import org.example.communication_room.dao.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface FriendshipRepository extends JpaRepository<Friendship, Long> {

    // 查找所有与指定用户相关的好友关系，无论是请求方还是接收方
    @Query("SELECT f FROM Friendship f WHERE f.requester.userId = :userId OR f.receiver.userId = :userId")
    List<Friendship> findAllByRequesterIdOrReceiverId(@Param("userId") Long userId1, @Param("userId") Long userId2);

    // 查找指定用户发起的好友请求
    List<Friendship> findByRequester(User requester);

    // 查找指定用户收到的好友请求
    List<Friendship> findByReceiver(User receiver);

    // 查找特定状态的好友关系
    List<Friendship> findByStatus(String status);
//    查看待通过申请状态好友关系
    List<Friendship> findByRequesterAndStatus(User requester, String status);
//    检查是否存在具有相同申请人和接收人的未处理好友请求
    boolean existsByRequesterAndReceiverAndStatus(User requester, User receiver, String status);
    boolean existsByRequesterAndReceiver(User requester, User receiver);

    Friendship findByReceiverAndRequester(User receiver, User requester);
    List<Friendship> findAllByRequesterAndStatus(@Param("requester") User requester, @Param("status") String status);
    Friendship findByRequesterAndReceiver(User requester, User receiver);


}
